﻿using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Threading;
using WPFExcelReport;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXBL
    {
        void DoYGRAB50CWork()
        {
            if (IsRun)
            {
                return;
            }
            IsRun = true;
            string path = @"C:\IntexReport\Data\YGRMU";
            string ITXDBVERSION = "YGR";
            YGRAB50C(ITXDBVERSION, path);
        }

        public void YGRAB50C(string ITXDBVERSION, string path)
        {
            try
            {
                List<DataRow> list;
                while (true)
                {
                    DataSet SetJob = GetJob(path);
                    if (SetJob.Tables.Count == 0)
                    {
                        IsRun = false;
                        break;
                    }
                    list = (List<DataRow>)CreateAB50(ITXDBVERSION, SetJob);
                    return;
                    if (list == null)
                        return;
                    string KRS = "", LFD = "", POS = "";
                    foreach (DataRow row in list)
                    {
                        if (row.Table.TableName == "ABPOS")
                        {
                            KRS = row["ABPAUFKRS"].ToString();
                            LFD = row["ABPAUFLFD"].ToString();
                            POS = row["ABPAUFPOS"].ToString();
                        }
                    }
                    DataRow dwData = INTEXDB.ICC_QUERYTB.NewRow();
                    var qABA = from DataRow row in SetJob.Tables["ICC_ABAX"].AsEnumerable()
                               where row["ABAAUFKRS"].ToString() == KRS
                               && row["ABAAUFLFD"].ToString() == LFD
                               && row["ABAAUFPOS"].ToString() == POS
                               select row;
                    foreach (DataRow row in qABA)
                    {
                        dwData["ZUMANDANT"] = MANDANT;
                        dwData["ZUAUFKRS"] = row["ABAVKAUFKRS"];
                        dwData["ZUAUFLFD"] = row["ABAVKAUFLFD"];
                        dwData["ZUAUFPOS"] = row["ABAVKAUFPOS"];
                        INTEXDBC.DeleteZUTEI(dwData, 2);
                        dwData["GAMANDANT"] = MANDANT;
                        dwData["GAAUFKRS"] = row["ABAVKAUFKRS"];
                        dwData["GAAUFLFD"] = row["ABAVKAUFLFD"];
                        dwData["GAAUFPOS"] = row["ABAVKAUFPOS"];
                        dwData["GASA"] = "713";
                        INTEXDBC.UpdateGAAUF(dwData, 3);
                        INTEXDBC.DeleteICC_ABAX(row, 6);
                        dwData["ABPMANDANT"] = MANDANT;
                        dwData["ABPAUFKRS"] = row["ABAVKAUFKRS"];
                        dwData["ABPAUFLFD"] = row["ABAVKAUFLFD"];
                        dwData["ABPAUFPOS"] = row["ABAVKAUFPOS"];
                        INTEXDBC.UpdateABPOS(dwData, 6);
                    }
                }
                EventDispatcher.Instance.RaiseStatus("转换完成", StatusEventType.StopProgress);
            }
            catch (Exception ex)
            {
                EventDispatcher.Instance.RaiseStatus("转换异常终止", StatusEventType.StopProgress);
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {
                IsRun = false;
            }
        }
     
    }
}